from fastapi import FastAPI, Request,status
from fastapi.responses import JSONResponse

from .paramException import ParamException
from .infoLackException import InfoLackException


def get_handlers(app: FastAPI):

    @app.exception_handler(ParamException)
    def ParamExceptionHandler(request: Request, exc: ParamException):
        return JSONResponse(
            status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
            content={"message": f"Parameters are not allowed, detail: {exc.description}"}
        )

    @app.exception_handler(InfoLackException)
    def InfoLackExceptionHandler(request: Request, exc: InfoLackException):
        return JSONResponse(
            status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
            content={"message": f"Information for specific tanker is too little to analysis, detail: {exc.description}"}
        )

